<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateAdminsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('admins', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name', 128);
            $table->string('avatar',256);
            $table->string('password',128);
            $table->string('encrypt',8);
            $table->unsignedTinyInteger('status')->comment('0停用1启用');
            $table->timestamp('last_login_time')->nullable()->comment('用户上次登陆时间');
            $table->string('last_login_ip')->nullable();
            $table->string('api_token')->nullable();
            $table->timestamp('api_token_expire_time')->nullable();
            $table->unsignedTinyInteger('role')->comment('0超级管理员1普通管理员');

            $table->timestamps();
            $table->index('api_token');
        });
        DB::table('admins')->insert(
            array(
                array(
                    'id' => 1,
                    'name' => 'admin',
                    'avatar' => 'default.jpg',
                    'password'=> 'bd2222b237c28fd448abe93d476a4f18',
                    'encrypt' => 'EBlT8D',
                    'status' => 1,
                    'last_login_time' => '2017-11-13 00:00:00',
                    'last_login_ip' => '',
                    'api_token' => '',
                    'api_token_expire_time' => '2017-11-13 00:00:00',
                    'role' => 0,
                    'created_at' => '2017-11-13 00:00:00',
                    'updated_at' => '2017-11-13 00:00:00'
                )
            ));
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('admins');
    }
}
